package com.lyt.springboot.util.algorithm;

import java.util.HashMap;
import java.util.Map;

public class S14 {
    public static void main(String[] args) {
        Map<String,String>  map  = new HashMap();


    }
    public String longestCommonPrefix (String[] strs) {
        // write code here
        if(strs.length == 0 || strs ==null) {
            return "";

        }
        StringBuilder builder = new StringBuilder();
        int len = strs[0].length();
        int count = strs.length;
        for (int i = 0; i < strs[0].length() ; i++) {
            for (int j = 0; j < count; j++) {
                if (i == strs[j].length() ||
                        strs[j].charAt(i) != strs[0].charAt(i)) { //边界条件
                    return strs[0].substring(0,i);                //循环里直接拼接 本质对于strs[0]裁剪
                }
            }
        }
        return strs[0];
    }
}
